<?php
/**
 * Description
 *
 * PHP version 7
 *
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-29 23:13:09
 * @lastTime 2020-05-02 00:21:14
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */
namespace Test\Unit;

use Design\Other\ServiceLocator\LogService;
use Design\Other\ServiceLocator\ServiceLocator;

class LocatorTest extends \Test\BaseTest
{

    private $locator;


    public function setUp() : void
    {
        $this->locator = new ServiceLocator();

    }//end setUp()


    public function testHasServices()
    {
        $this->locator->addInstance(LogService::class, new LogService());

        $this->assertTrue($this->locator->has(LogService::class));
        $this->assertFalse($this->locator->has(self::class));

    }//end testHasServices()


    public function testGetWillInstantiateLogService()
    {
        $this->locator->addClass(LogService::class, []);
        $service = $this->locator->get(LogService::class);

        $this->assertInstanceOf(LogService::class, $service);

        $serviceA = $this->locator->get(LogService::class);

        $this->assertEquals($service, $serviceA);

    }//end testGetWillInstantiateLogService()

    public function testCanThrowExceptionWhenGiveTooManyArguments()
    {
        $this->expectException(\OutOfBoundsException::class);
        $this->expectDeprecationMessage('Too many argument given');
        $this->locator->addClass(LogService::class, [1,2,3,4]);
        $this->locator->get(LogService::class);
    }

    public function testCanThrowExceptionWhenGiveWrongClass()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectDeprecationMessage('Could not instance service');
        $this->locator->addClass(\InvalidArgumentException::class, [1,2]);
        $this->locator->get(\InvalidArgumentException::class);
    }


}//end class
